<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>userAll</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
<div style="text-align: center;margin-top: 20px">
    <table class="table table-striped table-bordered table-hover table-condensed" id='tabletest' style="width: 1000px" align="center">
        <tr style="text-align: center">
            <th>用户ID：</th>
            <th>用户账号：</th>
            <th>用户密码：</th>
            <th>联系电话：</th>
            <th>操作方式：</th>
            <th><button style="width: 100px"  onclick="toWareHoeseAll()" type="button" class="btn btn-success">进入仓库</button></th>
        </tr>
    </table>
</div>

</body>
<script>
    $(document).ready(function (t) {
        $.ajax({
            type: 'GET',
            url: "http://49.235.107.34:8081/user/findAll",
            success: function (result) {
                for (var i in result.data) {
                    $("table").append(`
            <tr style="text-align: center">
                <td>${result.data[i].userId}</td>
                <td>${result.data[i].name}</td>
                <td>${result.data[i].password}</td>
                <td>${result.data[i].tel}</td>
                <td>
                    <button style="width: 60px" id="${result.data[i].userId}-${result.data[i].name}-${result.data[i].password}-${result.data[i].tel}" onclick="updateUser(this)" type="button" class="btn btn-success">修改</button>
                    <button style="width: 60px" id="${result.data[i].userId}" onclick="deleteUser(this)" type="button" class="btn btn-warning">删除</button>
                </td>
            </tr>
        `);
                }
            }

        });
    });

    function updateUser(t) {
        localStorage.id = t.id
        window.location.assign("http://49.235.107.34:8081/updateUser.html")
    }

    function deleteUser(t) {
        $.ajax({
            type: 'POST',
            url: "http://49.235.107.34:8081/user/delete",
            data: {"userId" : t.id},
            success: function (result) {
                if (result.code == 0){
                    window.location.assign("http://49.235.107.34:8081/userAll.html")
                } else {
                    alert("删除失败，请重试")
                }
            }
        })
    }

    function toWareHoeseAll() {
        window.location.assign("http://49.235.107.34:8081/wareHouseAll.html")
    }

</script>
</html>